package com.he.demo.req;

import lombok.extern.slf4j.Slf4j;

import java.text.MessageFormat;
import java.util.Map;

/**
 * @author heyanjing
 * date:2022-04-20 2022/4/20:0:28
 */
@Slf4j
public class ReqParams {
    public static String REQUEST_STR = "<Request>%s</Request>";
    public static String PARAMS_REQUEST_STR = "<Parms><Request>%s</Request></Parms>";


    public static String genRequest(Map<String, Object> params) {
        StringBuilder sb = new StringBuilder();
        for (String key : params.keySet()) {
            sb.append(MessageFormat.format("<{0}>{1}</{0}>", key, params.get(key)));
        }
        String format = String.format(REQUEST_STR, sb);
        log.info("请求参数  {}", format);
        return format;
    }
    public static String genParamsRequest(Map<String, Object> params) {
        StringBuilder sb = new StringBuilder();
        for (String key : params.keySet()) {
            sb.append(MessageFormat.format("<{0}>{1}</{0}>", key, params.get(key)));
        }
        String format = String.format(PARAMS_REQUEST_STR, sb);
        log.info("请求参数  {}", format);
        return format;
    }
}
